<?php
header('Content-Type: text/xml');
print "<?xml version='1.0' encoding='ISO-8859-1'?>";
print "<response><update>";
if ($error == true) print "failed";
else print "completed";
print "</update><msg>" . htmlspecialchars($msg) . "</msg><tank-vol>";
foreach ($converter as $key => $value) {
	print "<" . $key . ">";
	print number_format(round($result1 * $value,2),2);
	print "</" . $key . ">";
}
print "</tank-vol><substrate-vol>";
foreach ($converter as $key => $value) {
	print "<" . $key . ">";
	print number_format(round($result2 * $value,2),2);
	print "</" . $key . ">";
}
print "</substrate-vol><water-vol>";
foreach ($converter as $key => $value) {
	print "<" . $key . ">";
	print number_format(round($result3 * $value,2),2);
	print "</" . $key . ">";
}
print "</water-vol>";
if ($result2 > 0) {
	print "<substrate-quantities>";
	foreach ($substrate_densities as $key => $value) {
		print "<substrate-quantity>";
		print "<name>";
		print $key;
		print "</name><kg>";
		print round($result2 * $converter['LIT'] * $value,0);
		print "</kg><lb>";
		print round($result2 * $converter['LIT'] * $value * $kg2lb,0);
		print "</lb>";
		print "</substrate-quantity>";
	}
	
	print "</substrate-quantities><as-vol>";
	$q = "";
	$big = 0;
	$small = 0;
	if (($result2 * $converter['LIT']) < 9)
		$small = ceil($result2 * $converter['LIT'] / 3);
	else {
		$big = floor($result2 * $converter['LIT'] / 9);
		if (($result2 * $converter['LIT'] / 9) > $big) {
			$small = ceil((($result2 * $converter['LIT']) - (floor($result2 * $converter['LIT'] / 9)*9))/3);
		}
	}
	if (($small * 3) == 9) {
		$small = 0;
		$big = $big + 1;
	}
	if ($big > 0) $q = $big . " 9L";
	if ($small > 0 and $big > 0) $q = $q . " and ";
	if ($small > 0) $q = $q . $small . " 3L";
	$q = $q . " bag(s) of ADA Aquasoil Series";
	print $q;
	print "</as-vol>";
}
print "</response>";
?>
